import scrapy


class CtSpider(scrapy.Spider):
    name = 'ct'
    allowed_domains = ['chouti.com']
    start_urls = ['https://dig.chouti.com/']

    def parse(self, response):
        a_list = response.xpath("//div")

        for a_temp in a_list:
            title = a_temp.xpath(".//a[@class='link-title link-statistics']/text()").extract_first()
            from_s = a_temp.xpath(".//div[@class='link-from']/text()").extract_first()
            send_user = a_temp.xpath(".//div[1]/span[1]/span/text()").extract_first()
            img_url = a_temp.xpath(".//a[@class='common-matching-con left']/img/@src").extract_first()
            if img_url and img_url not in a_list:
                yield {
                    '标题':title,
                    '来源':from_s,
                    '发布人':send_user,
                    '图片链接':img_url
                }

